home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode Previous / Plug-In Samples / Plug-in - Postscript Renderer / IRS_Geometry.c next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  5.4 KB  |  209 lines  |  [TEXT/CWIE]

  1. /******************************************************************************\
  2.                                                                         
  3.         Module:        IRS_Geometry.c                                            
  4.                                                                             
  5.         Purpose:     plug-in renderer for QD3D: geometry rendering                                
  6.                                                                         
  7.         Author:        Sun-Inn Shih                                        
  8.                                                                         
  9.         Copyright (C) 1993-96 Apple Computer, Inc.  All rights reserved.    
  10.                                                                             
  11. \*****************************************************************************/
  12. #include <QD3D.h>
  13. #include <QD3DGeometry.h>
  14.  
  15. #include "IRS_Geometry.h"
  16.  
  17. /*
  18.  *  IRS_Geometry_Triangle 
  19.  */
  20. TQ3Status IRS_Geometry_Triangle(
  21.     TQ3ViewObject         pView,
  22.     irsData                *irsdata,
  23.     TQ3GeometryObject    pGeom, 
  24.     TQ3TriangleData        *pTriangleData)
  25. {
  26.     TQ3Point3D                point3D;
  27.     TQ3Point2D                point2D[3];
  28.  
  29.     float    w;
  30.     float     scale = irsdata->scale;
  31.     float     center = irsdata->center;    
  32.     long    j;
  33.  
  34.     /* local to Frustum */
  35.     float M00, M01, M02, M03;
  36.     float M10, M11, M12, M13;
  37.     float M20, M21, M22, M23;
  38.     float M30, M31, M32, M33;
  39.     
  40.     M00 = irsdata->localToFrustum.value[0][0];
  41.     M01 = irsdata->localToFrustum.value[0][1];
  42.     M02 = irsdata->localToFrustum.value[0][2];
  43.     M03 = irsdata->localToFrustum.value[0][3];
  44.  
  45.     M10 = irsdata->localToFrustum.value[1][0];
  46.     M11 = irsdata->localToFrustum.value[1][1];
  47.     M12 = irsdata->localToFrustum.value[1][2];
  48.     M13 = irsdata->localToFrustum.value[1][3];
  49.  
  50.     M20 = irsdata->localToFrustum.value[2][0];
  51.     M21 = irsdata->localToFrustum.value[2][1];
  52.     M22 = irsdata->localToFrustum.value[2][2];
  53.     M23 = irsdata->localToFrustum.value[2][3];
  54.  
  55.     M30 = irsdata->localToFrustum.value[3][0];
  56.     M31 = irsdata->localToFrustum.value[3][1];
  57.     M32 = irsdata->localToFrustum.value[3][2];
  58.     M33 = irsdata->localToFrustum.value[3][3];
  59.     
  60.     /* trimesh data */
  61.     scale = irsdata->scale;
  62.     center = irsdata->center;    
  63.     
  64.     for( j = 0 ; j < 3 ; j ++)
  65.     {
  66.         point3D = pTriangleData->vertices[j].point;
  67.         
  68.         point2D[j].x = point3D.x * M00 + point3D.y * M10 + point3D.z * M20 + M30;
  69.         point2D[j].y = point3D.x * M01 + point3D.y * M11 + point3D.z * M21 + M31;
  70.         w = point3D.x * M03 + point3D.y * M13 + point3D.z * M23 + M33;
  71.     
  72.         point2D[j].x = ( point2D[j].x / w ) * scale + center;
  73.         point2D[j].y = ( point2D[j].y / w ) * scale + center;
  74.     }    
  75.  
  76.     fprintf(irsdata->filePtr, "%d %d moveto ", (long) point2D[0].x, (long) point2D[0].y);
  77.     fprintf(irsdata->filePtr, "%d %d lineto ", (long) point2D[1].x, (long) point2D[1].y);
  78.     fprintf(irsdata->filePtr, "%d %d lineto ", (long) point2D[2].x, (long) point2D[2].y);
  79.     fprintf(irsdata->filePtr, "closepath\n" );
  80.  
  81.     return kQ3Success;
  82. }
  83.  
  84. /*
  85.  *  IRS_Geometry_Line 
  86.  */
  87. TQ3Status IRS_Geometry_Line(
  88.     TQ3ViewObject         pView,
  89.     irsData                *irsdata,
  90.     TQ3GeometryObject    pGeom, 
  91.     TQ3LineData            *pLineData)
  92. {
  93.     return kQ3Success;
  94. }
  95.  
  96. /*
  97.  *  IRS_Geometry_Point 
  98.  */
  99. TQ3Status IRS_Geometry_Point(
  100.     TQ3ViewObject         pView,
  101.     irsData                *irsdata,
  102.     TQ3GeometryObject     pGeom, 
  103.     TQ3PointData        *pPointData)
  104. {
  105.     return kQ3Success;
  106. }
  107.  
  108. /*
  109.  *  IRS_Geometry_Marker 
  110.  */
  111. TQ3Status IRS_Geometry_Marker(
  112.     TQ3ViewObject         pView,
  113.     irsData                *irsdata,
  114.     TQ3GeometryObject     pGeom, 
  115.     TQ3MarkerData        *pMarkerData)
  116. {
  117.     return kQ3Success;
  118. }
  119.  
  120. /*
  121.  *  IRS_Geometry_PixmapMarker 
  122.  */
  123. TQ3Status IRS_Geometry_PixmapMarker(
  124.     TQ3ViewObject         pView,
  125.     irsData                    *irsdata,
  126.     TQ3GeometryObject     pGeom, 
  127.     TQ3PixmapMarkerData    *pPixmapMarkerData)
  128. {
  129.     return kQ3Success;
  130. }
  131.  
  132. #if 0
  133. /*
  134.  *  IRS_Geometry_TM 
  135.  */
  136. TQ3Status IRS_Geometry_TM(
  137.     TQ3ViewObject         pView,
  138.     irsData                *irsdata,
  139.     TQ3GeometryObject    pGeom, 
  140.     TQ3TriMeshData        *pTriMeshData)
  141. {
  142.     /* QD3D structures */
  143.     TQ3TriMeshTriangleData *trianglelist;
  144.     TQ3Point3D                point3D, *pointlist;
  145.     TQ3Point2D                point2D[3];
  146.  
  147.     float    w;
  148.     float     scale = irsdata->scale;
  149.     float     center = irsdata->center;    
  150.     long    i, j, index;
  151.  
  152.     /* local to Frustum */
  153.     float M00, M01, M02, M03;
  154.     float M10, M11, M12, M13;
  155.     float M20, M21, M22, M23;
  156.     float M30, M31, M32, M33;
  157.     
  158.     M00 = irsdata->localToFrustum.value[0][0];
  159.     M01 = irsdata->localToFrustum.value[0][1];
  160.     M02 = irsdata->localToFrustum.value[0][2];
  161.     M03 = irsdata->localToFrustum.value[0][3];
  162.  
  163.     M10 = irsdata->localToFrustum.value[1][0];
  164.     M11 = irsdata->localToFrustum.value[1][1];
  165.     M12 = irsdata->localToFrustum.value[1][2];
  166.     M13 = irsdata->localToFrustum.value[1][3];
  167.  
  168.     M20 = irsdata->localToFrustum.value[2][0];
  169.     M21 = irsdata->localToFrustum.value[2][1];
  170.     M22 = irsdata->localToFrustum.value[2][2];
  171.     M23 = irsdata->localToFrustum.value[2][3];
  172.  
  173.     M30 = irsdata->localToFrustum.value[3][0];
  174.     M31 = irsdata->localToFrustum.value[3][1];
  175.     M32 = irsdata->localToFrustum.value[3][2];
  176.     M33 = irsdata->localToFrustum.value[3][3];
  177.     
  178.     /* trimesh data */
  179.     trianglelist = pTriMeshData->triangles;
  180.     pointlist = pTriMeshData->points;
  181.  
  182.     scale = irsdata->scale;
  183.     center = irsdata->center;    
  184.     
  185.     for(i=0;i<pTriMeshData->numTriangles; i++, trianglelist++)
  186.     {
  187.         for( j = 0 ; j < 3 ; j ++)
  188.         {
  189.             index = trianglelist->pointIndices[j];
  190.             point3D = pointlist[index];
  191.             
  192.             point2D[j].x = point3D.x * M00 + point3D.y * M10 + point3D.z * M20 + M30;
  193.             point2D[j].y = point3D.x * M01 + point3D.y * M11 + point3D.z * M21 + M31;
  194.             w = point3D.x * M03 + point3D.y * M13 + point3D.z * M23 + M33;
  195.         
  196.             point2D[j].x = ( point2D[j].x / w ) * scale + center;
  197.             point2D[j].y = ( point2D[j].y / w ) * scale + center;
  198.         }    
  199.     
  200.         fprintf(irsdata->filePtr, "%d %d moveto ", (long) point2D[0].x, (long) point2D[0].y);
  201.         fprintf(irsdata->filePtr, "%d %d lineto ", (long) point2D[1].x, (long) point2D[1].y);
  202.         fprintf(irsdata->filePtr, "%d %d lineto ", (long) point2D[2].x, (long) point2D[2].y);
  203.         fprintf(irsdata->filePtr, "closepath\n" );
  204.     }
  205.         
  206.     return kQ3Success;
  207. }
  208. #endif
  209.